<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/admin/jsp/common/HtmlHead.jsp"/>
<title>Insert title here</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function(){
	var tea;
	$("#teacher").keyup(function(){
		document.getElementById('teacherId').value='';
		if(this.innerHTML!=''&&tea!=this.innerHTML){
			tea = this.innerHTML;
			$.getJSON("<s:url action="ajaxGetTeachers" namespace="/admin/teacher"/>",{"teacher.realName":this.innerHTML},function(data){
				if(data){
					var div = $(".sel_box");
					div.empty();
					if(data.length>0){
						if(data.length>1){
							for(var i=0;i<data.length;i++){
								var a = $("<a class='item'></a>");
								a.data("key",data[i].id);
								a.data("value",data[i].realName);
								a.text(data[i].realName);
								a.click(function(){
									document.getElementById('teacher').innerHTML=$(this).data('value');
									document.getElementById('teacherId').value=$(this).data('key');
									div.hide();
								});
								div.append(a);
							}
							div.show();
						}else{
							document.getElementById('teacher').innerHTML=data[0].realName;
							document.getElementById('teacherId').value=data[0].id;
						}
					}
				}
			});
		}
	});
});
</script>
<style>
.sel_box{position:absolute;z-index:99;width:80px;background-color: #ffffff;border:1px #000000 solid;display:none;}
.sel_box .item{display:block;float:left;width:80px;overflow:hidden;}
</style>
</head>
<body>
	<s:form action="editDo" method="post" enctype="multipart/form-data">
		<s:hidden name="course.id"/>
		<s:hidden name="course.classId"/>
		<table width="100%">
			<tr>
				<th>课程名称</th>
				<td>
					<s:textfield name="course.name"/>
				</td>
			</tr>
			<tr>
				<th>所属班级</th>
				<td>
					<s:textfield name="course.className" value="%{getClassName(course.classId)}" disabled="true"/>
				</td>
			</tr>
			<tr>
				<th>授课教师</th>
				<td>
					<!-- s:textfield name="course.teacherName" id="teacher"/-->
					<div id="teacher" designMode="On" contentEditable="true" style="height:16px;width:80px;border:1px #000 solid;"></div>
					<div class='sel_box' style="display:none"></div>
					<s:textfield name="course.teacherId" id="teacherId"/>
				</td>
			</tr>
			<tr>
				<th>所属科目</th>
				<td>
					<s:select list="subjectList" listKey="id" listValue="name" name="course.subjectId"></s:select>
				</td>
			</tr>
			<tr>
				<th>相关图片</th>
				<td>
					<s:hidden name="course.imgUrl" id="imgUrl"/>
					<img id="courseImg" src="<s:property value="course.imgUrl"/>"/><br/>
					<input type="file" id="u_file" name="fileData" />
				</td>
			</tr>
			<tr>
				<th>课程介绍</th>
				<td><s:textarea name="course.description"/>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="submit" value="提交"/>
				</td>
			</tr>
		</table>
	</s:form>
</body>
<jsp:include page="/admin/jsp/common/errorMessage.jsp"/>
</html>